<?php

require_once 'db.php';

class work extends DB {

    public function works1() {
        $this->getConnection();
        $query = "SELECT * FROM works LIMIT 0,50";
        $work = $this->query($query);
        return $work;
    }

    public function select($query) {
        $works = $this->query($query);
        return $works;
    }
    public function works($id = null, $page = NULL) {
        $this->getConnection();
        $where = "";

        if (!empty($id))
            $where = "where id= $id";
        $limit = "";
        if (!empty($page))
            $limit = "limit" . $in . ',' . PER_PAGE;
        $in = ($page - 1) * PER_PAGE;
        $query = "SELECT * FROM works $where $limit";
        $worka = $this->query($query);
        return $worka;
    }
    
        public function select_edit($page = NULL, $id = NULL) {
        $this->getConnection();
        $where = "";
        if (!empty($id))
            $where = "where id=$id";
        $limit = "";
        if (!empty($page))
            $limit = 'limit ' . $begin . ',' . PER_PAGE;
        $begin = ($page - 1) * PER_PAGE;
        $query = "SELECT * FROM works $where $limit";
        $result = mysql_query($query);
        $result = mysql_fetch_assoc($result);
        return $result;
    }
    
    
    public function update($array = null) {
        $query = "Update works set name='" . $array['name'] .
                 "', posted='" . $array['posted'] .
                 "', image='" . $array['image'].
                 "', description='" . $array['description'].
                 "' where id=" . $array['id'];
        mysql_query($query);
        if (mysql_query($query))
            echo "ok";
        else
            echo "fail";
    }
    public function update_kohinh($array = null) {
        $query = "Update works set name='" . $array['name'] .
                 "', posted='" . $array['posted'] .
                "', description='" . $array['description'].
                 "' where id=" . $array['id'];
        mysql_query($query);
        if (mysql_query($query))
            echo "Ok";
        else
            echo "fail";
    }
}
?>

